package config;

import com.jfinal.config.*;
import com.jfinal.ext.handler.ContextPathHandler;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import controller.MainController;
import controller.WxController;
import model.Draw;
import model.Prize;
import model.User;
import model.WechatCache;

/**
 * Created by wp1988 on 2016/8/15 0015.
 */
public class MaopuConfig extends JFinalConfig {

    @Override
    public void configConstant(Constants me) {
        me.setDevMode(true);//设置为开发模式
//        me.setViewType(ViewType.JSP);//返回视图类型默认为freemaker,此时可不加此句
    }

    @Override
    public void configHandler(Handlers me) {
        me.add(new ContextPathHandler("maopu"));
    }

    @Override
    public void configInterceptor(Interceptors me) {

    }

    @Override
    public void configPlugin(Plugins me) {
        C3p0Plugin cp = new C3p0Plugin("jdbc:mysql://localhost/maopu", "root", "root");
        //C3p0Plugin cp = new C3p0Plugin("jdbc:mysql://localhost/maopu", "root", "3864fdb53a");
        me.add(cp);
        ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
        me.add(arp);
        arp.addMapping("user", "user_id", User.class);
        arp.addMapping("draw", Draw.class);
        arp.addMapping("prize", Prize.class);
        arp.addMapping("wechat_cache", WechatCache.class);
    }

    @Override
    public void configRoute(Routes me) {
        me.add("/", MainController.class, "/");
        me.add("/wx", WxController.class, "/");
    }
}
